package top.kaoshanji.p3ch12a.component;

/**
 * 代码清单-p3ch12a-402页a：不使用泛型的并行继承层次结构的实现示例
 * author kaoshanji
 * ^_^
 * create time 2025/2/6 20:04
 */
public class NormalComponent {

    public void render() {
        ButtonRenderer renderer = new ButtonRenderer();
        renderer.render(new Button());
        renderer.render(new Lable()); // 编译正确，运行时错误
    }

}


abstract class Component {}

abstract class ComponentRenderer {
    abstract void render(Component window);
}

class Button extends Component {}

class Lable extends Component {}

class ButtonRenderer extends ComponentRenderer {

    @Override
    void render(Component window) {
        if (window instanceof Button) {
            // 界面渲染
        } else {
            throw new IllegalArgumentException();
        }
    }
}
